package com.hexu.event.view;


import com.hexu.event.bean.TicketHistoryBean;
import com.hexu.event.entity.TicketHistory;
import com.hexu.event.util.StageUtil;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.geometry.Insets;
import javafx.scene.Scene;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.control.cell.PropertyValueFactory;
import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;

import java.util.ArrayList;
import java.util.List;

public class TicketHistoryTableView {

    public void viewTicketHistoryInformation(int ticketHistoryNumber,List<TicketHistory> ticketHistoryList) {

        List<TicketHistoryBean> ticketHistoryBeanList = new ArrayList<>();

        TableView<TicketHistoryBean> table = new TableView<>();

        for(int i = 0;i<ticketHistoryNumber;i++){
            //添加购票历史信息
            ticketHistoryBeanList.add(  new TicketHistoryBean(ticketHistoryList.get(i).getAttractionsName(),ticketHistoryList.get(i).getTicketFare(),
                    ticketHistoryList.get(i).getUserPhoneNumber(),ticketHistoryList.get(i).getBuyTime())
            );
        }
        //转化成表可存放的数据
        final ObservableList<TicketHistoryBean> data =
                FXCollections.observableArrayList(
                        ticketHistoryBeanList
                );


        //景点名字
        //列的数据类型
        TableColumn<TicketHistoryBean,String> nameCol =
                new TableColumn<>("景点名字");
        //设置出是最小宽度
        nameCol.setMinWidth(100);
        nameCol.setCellValueFactory(
                new PropertyValueFactory<>("attractionsName"));
        //用户手机号码
        TableColumn<TicketHistoryBean, String> phoneNumberCol =
                new TableColumn<>("手机号码");
        phoneNumberCol.setMinWidth(125);
        phoneNumberCol.setCellValueFactory(
                new PropertyValueFactory<>("phoneNumber"));
        //门票价格
        TableColumn<TicketHistoryBean, Integer> ticketFareCol = new TableColumn<>("门票价格");
        ticketFareCol.setMinWidth(75);
        ticketFareCol.setCellValueFactory(
                new PropertyValueFactory<>("ticketFare"));
        //购票时间
        TableColumn<TicketHistoryBean,String> buyTimeCol = new TableColumn<>("购票时间");
        buyTimeCol.setMinWidth(175);
        buyTimeCol.setCellValueFactory(
                new PropertyValueFactory<>("buyTime"));

        //接收信息
        table.setItems(data);
        //把数据放在相应列里
        table.getColumns().addAll(nameCol,ticketFareCol,phoneNumberCol, buyTimeCol);

        final VBox vbox = new VBox();
        vbox.setSpacing(5);
        vbox.setPadding(new Insets(10, 0, 0, 10));

        HBox hb = new HBox();
        vbox.getChildren().addAll(table, hb);

        StageUtil.showStage(new Stage(),new Scene(vbox),550,475,"购票历史",false);
    }
}